package org.linlinjava.litemall.db.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.linlinjava.litemall.db.dao.BrandMapper;
import org.linlinjava.litemall.db.models.Brand;
import org.linlinjava.litemall.db.service.BrandService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand>
        implements BrandService {

    @Override
    public IPage<Brand> query(Integer pageNo, Integer pageSize) {
        Page<Brand> page = new Page<>(pageNo, pageSize);
        return this.baseMapper.selectPage(page, new QueryWrapper<Brand>());
    }

    @Override
    public IPage<Brand> querySelective(String id, String name, Integer pageNo, Integer pageSize) {
        Page<Brand> page = new Page<>(pageNo, pageSize);
        QueryWrapper<Brand> query = new QueryWrapper<>();
        query.eq(!StringUtils.isEmpty(id), "id", id);
        query.eq(!StringUtils.isEmpty(name), "name", name);
        return this.baseMapper.selectPage(page, query);
    }

    @Override
    public List<Brand> all() {
        return baseMapper.selectList(new QueryWrapper<Brand>());
    }
}
